/*******************************************************************************
  * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.
  * @file     circularPBar.c
  * @author   UartTFT Application Team
  * @version  V0.0.1
  * @date     2023-01-04
  * @brief    This file contains the functions prototypes for the UartTFT
  *           Application display firmware.
 ********************************************************************************/
#include "circularPBar.h"
#include "bsp.h"
#include "function.h"
#include "sincos_table.h"
#include "string.h"
#include "math.h"
#include "stdio.h"

#include "uiIcon.h"
#include "popupBox.h"
#include "levetop.h"
#include "transport.h"
#include "uart.h"
#include "function_drv.h"
#include "css_psram.h" //hdz

/***********************************************************************************
* Function Name	: Circular_progress_bar
* Description	: Display ring progress bar.
* Input         : - type: ring info sources
				  - buff: ring info
* Output        : None
* Return        : None
************************************************************************************/
void Circular_progress_bar(uint8_t type, uint8_t *buff)
{
	uint8_t I_num, D_num, Alig, zk_id, flag, n = 0, i = 0, kk = 0, flag1 = 0;
	uint8_t buff1[16],Symbol = 0;
	uint16_t temp, xd = 0;
	uint16_t pointer, p_add, x, y, dx, dy, fornt_id, bg_id, Sangle, Eangle;
	uint16_t S_id, E_id;
	int16_t Vmax, Vmin, angle,tt,value1;
	int32_t value, ll;
	uint16_t xR, yR;
	uint16_t num_w, dot_w, h, canvas_numw, canvas_dotw ,w0 = 0, h0 = 0;
	uint32_t color, zk_addr;
	uint16_t ring_R, ring_CX, ring_CY; // ring radius,centre point
	int32_t hh;
	uint16_t overlay = 0;
	uint16_t buff_x,buff_y,buff_w;
	uint32_t psram_addr = 0;

	if (type == 0) // instruction information source is configuration file
	{
		p_add = (buff[5] + (buff[6] << 8));
		x = buff[7] + (buff[8] << 8);
		y = buff[9] + (buff[10] << 8);
		fornt_id = buff[11] + (buff[12] << 8);
		bg_id = buff[13] + (buff[14] << 8);
		Vmin = buff[15] + (buff[16] << 8);
		Vmax = buff[17] + (buff[18] << 8);
		Sangle = buff[19] + (buff[20] << 8);
		Eangle = buff[21] + (buff[22] << 8);
		dx = buff[23] + (buff[24] << 8);
		dy = buff[25] + (buff[26] << 8);
		I_num = buff[27];
		D_num = buff[28];
		Alig = buff[29];
		zk_id = buff[30];
		color = buff[31] + (buff[32] << 8) + (buff[33] << 16);
		S_id = buff[34] + (buff[35] << 8);
		E_id = buff[36] + (buff[37] << 8);
		flag = buff[38];
		overlay = buff[39] + (buff[40] << 8);
	}
	else if (type == 1) // instruction information ource is variable space
	{
		pointer = (buff[2] + (buff[3] << 8)) * 2;
		p_add = (var[pointer + 1] + (var[pointer + 2] << 8));
		x = var[pointer + 3] + (var[pointer + 4] << 8);
		y = var[pointer + 5] + (var[pointer + 6] << 8);
		fornt_id = var[pointer + 7] + (var[pointer + 8] << 8);
		bg_id = var[pointer + 9] + (var[pointer + 10] << 8);
		Vmin = var[pointer + 11] + (var[pointer + 12] << 8);
		Vmax = var[pointer + 13] + (var[pointer + 14] << 8);
		Sangle = var[pointer + 15] + (var[pointer + 16] << 8);
		Eangle = var[pointer + 17] + (var[pointer + 18] << 8);
		dx = var[pointer + 19] + (var[pointer + 20] << 8);
		dy = var[pointer + 21] + (var[pointer + 22] << 8);
		I_num = var[pointer + 23];
		D_num = var[pointer + 24];
		Alig = var[pointer + 25];
		zk_id = var[pointer + 26];
		color = var[pointer + 27] + (var[pointer + 28] << 8) + (var[pointer + 29] << 16);
		S_id = var[pointer + 30] + (var[pointer + 31] << 8);
		E_id = var[pointer + 32] + (var[pointer + 33] << 8);
		flag = var[pointer + 34];
		overlay = var[pointer + 35] + (var[pointer + 36] << 8);
	}

	if (Pop_up_flag == 1) // Popup offset
	{
		x += Pop_up_x;
		y += Pop_up_y;
		dx += Pop_up_x;
		dy += Pop_up_y;
	}
	if(download_flag == 3 || download_flag == 1)
	{
		psram_addr = LCD_XSIZE_TFT * LCD_YSIZE_TFT * 2 ;
	}
	if(download_flag == 3 )
	{
		if (Screen_DIR == 0 || Screen_DIR == 2)
		{
			x += LCD_XSIZE_TFT * 2;
			dx += LCD_XSIZE_TFT * 2;
		}
		else if (Screen_DIR == 1 || Screen_DIR == 3)
		{
			y += LCD_YSIZE_TFT * 2;
			dy += LCD_YSIZE_TFT * 2;
		}
	}



	if (bg_id <= addr_index[11])
	{
		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * bg_id + multi_language * 12 * addr_index[11], 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

		if(pic_flag == ColorARGB0565 || pic_flag == ColorARGB4444 || pic_flag == ColorARGB8565)
		{
			if (pic_update == 0)
				LT268_BG_to_buffer(0,0,pic_w,m_PngData,
								   x, y,pic_w, pic_h);
		}

		if (pic_len != 0 && pic_flag != 0xFF)
		{
			if (pic_update == 0)
				LT268_pic_to_buffer(0, 0, pic_w, m_PngData,
									0, 0, pic_w, pic_add,
									pic_w, pic_h, pic_flag);
			else
				LT268_pic_to_buffer(x, y, FullScreen_w, m_PngData,
									0, 0, pic_w, pic_add,
									pic_w, pic_h, pic_flag);
		}

		LT_ReadFlash_UI(buff1, addr_index[10] + 12 * fornt_id + multi_language * 12 * addr_index[11], 12);
		pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		pic_w = buff1[4] + (buff1[5] << 8);
		pic_h = buff1[6] + (buff1[7] << 8);
		pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
		pic_flag = buff1[11];

	}
	else  //  BG == fullscreen
	{
		if(fornt_id <= addr_index[11])
		{
			LT_ReadFlash_UI(buff1, addr_index[10] + 12 * fornt_id + multi_language * 12 * addr_index[11], 12);
			pic_add = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
			pic_w = buff1[4] + (buff1[5] << 8);
			pic_h = buff1[6] + (buff1[7] << 8);
			pic_len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
			pic_flag = buff1[11];

			if(pic_flag == ColorARGB0565 || pic_flag == ColorARGB4444 || pic_flag == ColorARGB8565)
			{
				if (pic_update == 0)
					LT268_BG_to_buffer(0,0,pic_w,m_PngData,
										x, y,pic_w, pic_h);
			}

		}
		else  return;
	}

	if (pic_w % 2)
	{
		ring_R = pic_w / 2 + 1;
		ring_CX = pic_w / 2;
		ring_CY = pic_h / 2;
	}
	else
	{
		ring_R = pic_w / 2;
		ring_CX = pic_w / 2 - 1;
		ring_CY = pic_h / 2 - 1;
	}

	tt = (var[p_add * 2] << 8) + var[p_add * 2 + 1];

	if (tt <= Vmin)
		angle = Sangle;
	else if (tt >= Vmax)
		angle = Eangle;
	else
		angle = (Eangle - Sangle) * (tt - Vmin) / (Vmax - Vmin) + Sangle;

	if (Screen_DIR == 1)
	{
		angle = angle + 90;
		angle = angle % 360;
	}
	else if (Screen_DIR == 2)
	{
		angle = angle + 180;
		angle = angle % 360;
	}
	if (Screen_DIR == 3)
	{
		angle = angle + 270;
		angle = angle % 360;
	}

	if(pic_update == 0)
	{
		buff_x = 0;
		buff_y = 0;
		buff_w = pic_w;
	}
	else
	{
		buff_x = x;
		buff_y = y;
		buff_w = FullScreen_w;
	}

	if (angle == 0)
	{
		if (Screen_DIR == 1)
		{
			LT268_pic_to_buffer(buff_x, buff_y, buff_w, m_PngData,
								0, 0, pic_w, pic_add,
								pic_w, pic_h / 2, pic_flag);

			LT268_pic_to_buffer(ring_CX + buff_x, ring_CY + buff_y, buff_w, m_PngData,
								ring_CX, ring_CY, pic_w, pic_add,
								ring_R, pic_h / 2, pic_flag);
		}
		else if (Screen_DIR == 2)
		{
			LT268_pic_to_buffer(ring_CX + buff_x, buff_y, buff_w, m_PngData,
								ring_CX, 0, pic_w, pic_add,
								ring_R, pic_h, pic_flag);
		}
		else if (Screen_DIR == 3)
		{
			LT268_pic_to_buffer(ring_CX + buff_x, ring_CY + buff_y, buff_w, m_PngData,
								ring_CX, ring_CY, pic_w, pic_add,
								ring_R, pic_h / 2, pic_flag);
		}
	}
	else if ((angle>0)&&(angle<=90))
	{
		if (Screen_DIR == 1)
		{
			LT268_pic_to_buffer(buff_x, buff_y, buff_w, m_PngData,
								0, 0, pic_w, pic_add,
								pic_w, pic_h / 2, pic_flag);

			LT268_pic_to_buffer(ring_CX + buff_x, ring_CY + buff_y, buff_w, m_PngData,
								ring_CX, ring_CY, pic_w, pic_add,
								ring_R, pic_h / 2, pic_flag);
		}
		else if (Screen_DIR == 2)
		{
			LT268_pic_to_buffer(ring_CX + buff_x, buff_y, buff_w, m_PngData,
								ring_CX, 0, pic_w, pic_add,
								ring_R, pic_h, pic_flag);
		}
		else if (Screen_DIR == 3)
		{
			LT268_pic_to_buffer(ring_CX + buff_x, ring_CY + buff_y, buff_w, m_PngData,
								ring_CX, ring_CY, pic_w, pic_add,
								ring_R, pic_h / 2, pic_flag);
		}

		for (uint16_t yy = ring_CY; yy < pic_h; yy++)
		{
			hh=ring_CX-(yy-ring_CY)*FastTan(angle)/MAGNIFICATION;
			LT_ReadFlash_UI(DMA_rxbuf1, pic_add+pic_w*yy*2, ring_R*2);
#if LT_PSRAM
			LT_CSS_PSRAM_Read_QPI_DMA(buff_w * (yy + buff_y) * 2 + buff_x * 2, m_PngData, ring_R*2);
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx>hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[xx], &p16_DMA_rxbuf1[xx], pic_flag);
			}
			LT_CSS_PSRAM_Write_QPI_DMA(buff_w * (yy + buff_y) * 2 + buff_x * 2 + psram_addr, m_PngData, ring_R*2);
#else
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx>hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[buff_w*(yy + buff_y) + xx + buff_x], &p16_DMA_rxbuf1[xx], pic_flag);
			}
#endif
		}
	}
	else if((angle>90)&&(angle<=180))
	{
		if (Screen_DIR == 0)
		{
			LT268_pic_to_buffer(buff_x, ring_CY + buff_y, buff_w, m_PngData,
								0, ring_CY, pic_w, pic_add,
								ring_R, pic_h - ring_CY, pic_flag);
		}
		else if (Screen_DIR == 2)
		{

			LT268_pic_to_buffer(ring_CX + buff_x, buff_y, buff_w, m_PngData,
								ring_CX, 0, pic_w, pic_add,
								ring_R, pic_h, pic_flag);

			LT268_pic_to_buffer(buff_x, ring_CY + buff_y, buff_w, m_PngData,
								0, ring_CY, pic_w, pic_add,
								ring_R, pic_h / 2, pic_flag);
		}
		else if (Screen_DIR == 3)
		{
			LT268_pic_to_buffer(buff_x, ring_CY + buff_y, buff_w, m_PngData,
								0, ring_CY, pic_w, pic_add,
								pic_w, pic_h / 2, pic_flag);
		}

		for (uint16_t yy = 0; yy < ring_R; yy++)
		{
			hh=ring_CX-(ring_CY-yy)*MAGNIFICATION/FastTan(angle-90);

				if(hh>ring_R)
					break;
			LT_ReadFlash_UI(DMA_rxbuf1, pic_add+pic_w*yy*2, ring_R*2);

#if LT_PSRAM
			LT_CSS_PSRAM_Read_QPI_DMA(buff_w * (yy + buff_y) * 2 + buff_x * 2, m_PngData, ring_R*2);
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx<hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[xx], &p16_DMA_rxbuf1[xx], pic_flag);
			}
			LT_CSS_PSRAM_Write_QPI_DMA(buff_w * (yy + buff_y) * 2 + buff_x * 2 + psram_addr, m_PngData , ring_R*2);
#else
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx<hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[buff_w*(yy + buff_y) + xx + buff_x], &p16_DMA_rxbuf1[xx], pic_flag);
			}
#endif

		}

	}
	else if((angle>180)&&(angle<=270))
	{
		if (Screen_DIR == 0)
		{
			LT268_pic_to_buffer(buff_x, buff_y, buff_w, m_PngData,
								0, 0, pic_w, pic_add,
								ring_R, pic_h, pic_flag);
		}
		else if (Screen_DIR == 1)
		{
			LT268_pic_to_buffer(buff_x, buff_y, buff_w, m_PngData,
								0, 0, pic_w, pic_add,
								ring_R, pic_h / 2, pic_flag);
		}
		else if (Screen_DIR == 3)
		{
			LT268_pic_to_buffer(buff_x, buff_y, buff_w, m_PngData,
								0, 0, pic_w, pic_add,
								ring_R, pic_h / 2, pic_flag);


			LT268_pic_to_buffer(buff_x, ring_CY + buff_y, buff_w, m_PngData,
								0, ring_CY, pic_w, pic_add,
								pic_w, pic_h / 2, pic_flag);
		}

		for (uint16_t yy = 0; yy < ring_R; yy++)
		{
			hh=(ring_CY-yy)*FastTan(angle-180)/MAGNIFICATION;
			LT_ReadFlash_UI(DMA_rxbuf1, pic_add+pic_w*yy*2+ring_CX*2, ring_R*2);
#if LT_PSRAM
			LT_CSS_PSRAM_Read_QPI_DMA(buff_w * (yy + buff_y) * 2 + (buff_x + ring_CX) * 2, m_PngData, ring_R*2);
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx<hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[xx], &p16_DMA_rxbuf1[xx], pic_flag);
			}
			LT_CSS_PSRAM_Write_QPI_DMA(buff_w * (yy + buff_y) * 2 + (buff_x + ring_CX) * 2 + psram_addr, m_PngData, ring_R*2);
#else
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx<hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[buff_w*(yy + buff_y) + xx + buff_x + ring_CX], &p16_DMA_rxbuf1[xx], pic_flag);
			}
#endif
		}

	}
	else if((angle>270)&&(angle<=360))
	{
		if (Screen_DIR == 0)
		{
			LT268_pic_to_buffer(buff_x, buff_y, buff_w, m_PngData,
								0, 0, pic_w, pic_add,
								pic_w, ring_R, pic_flag);
			LT268_pic_to_buffer(buff_x, ring_CY + buff_y, buff_w, m_PngData,
								0, ring_CY, pic_w, pic_add,
								ring_R, pic_h-ring_CY, pic_flag);
		}
		else if (Screen_DIR == 1)
		{
			LT268_pic_to_buffer(buff_x, buff_y, buff_w, m_PngData,
								0, 0, pic_w, pic_add,
								pic_w, ring_R, pic_flag);
		}
		else if (Screen_DIR == 2)
		{

			LT268_pic_to_buffer(ring_CX + buff_x, buff_y, buff_w, m_PngData,
								ring_CX, 0, pic_w, pic_add,
								ring_R, pic_h-ring_CY, pic_flag);
		}

		for (uint16_t yy = ring_CY; yy < pic_h; yy++)
		{
			hh=(yy-ring_CY)*MAGNIFICATION/FastTan(angle-270);

			LT_ReadFlash_UI(DMA_rxbuf1, pic_add+pic_w*yy*2+(ring_CX+1)*2, ring_R*2);
#if LT_PSRAM
			LT_CSS_PSRAM_Read_QPI_DMA(buff_w * (yy + buff_y) * 2 + (buff_x + ring_CX + 1) * 2, m_PngData, ring_R*2);
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx>=hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[xx], &p16_DMA_rxbuf1[xx], pic_flag);
			}
			LT_CSS_PSRAM_Write_QPI_DMA(buff_w * (yy + buff_y) * 2 + (buff_x + ring_CX + 1) * 2 + psram_addr, m_PngData, ring_R*2);
#else
			for (uint16_t xx = 0; xx < ring_R; xx++)
			{
				if(xx>=hh)
					LT268_buffer_pixel_blending(&p16_m_PngData[buff_w*(yy + buff_y) + xx + buff_x + ring_CX + 1], &p16_DMA_rxbuf1[xx], pic_flag);
			}
#endif
		}
	}

	if (flag == 1)
	{
		LT_ReadFlash_UI(buff1, addr_index[2] + zk_id * 8, 4);
		zk_addr = buff1[0] + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
		memset(Display_buff, 0, 20);
		value1 = (var[p_add * 2] << 8) + var[p_add * 2 + 1];

		if (value1 < 0)
		{
			Display_buff[kk] = '-';
			kk++;
			value = ~value1 + 1;
		}
		else
		{
			value = value1;
		}
		value = value % ((int)LtPow(10, I_num + D_num));

		for (i = 0; i < I_num; i++) // Integer part
		{
			Display_buff[kk] = value / (int)LtPow(10, I_num - i - 1 + D_num) + '0';

			if (Display_buff[kk] != 0 || flag1 == 1)
			{
				kk++;
				flag1 = 1;
			}
			value = value % (int)LtPow(10, I_num - i - 1 + D_num);
		}
		if (D_num > 0)
		{
			if (flag1 == 0)
			{
				Display_buff[kk] = '0'; //"."
				kk++;
			}
			Display_buff[kk] = '.'; //"."
			kk++;
		}
		else if (flag1 == 0)
		{
			Display_buff[kk] = '0'; //"."
			kk++;
		}

		for (i = 0; i < D_num; i++) // Fractional part
		{
			Display_buff[kk] = value / (int)LtPow(10, D_num - i - 1) + '0';
			kk++;
			value = value % (int)LtPow(10, i - 1 + D_num);
		}

		LT_ReadFlash_UI(buff1, zk_addr, 4);

		LT_Print_zk_Font_BUFF(4, zk_addr,
							  LAY_BUFF1, LCD_XSIZE_TFT, buff1[2], buff1[3], Alig + 9, color, Black, 0,0,
							  buff_w, pic_h, m_PngData, dx - x + buff_x, dy - y + buff_y,pic_w,pic_h,
							  0, 0, Display_buff, sizeof(Display_buff));
	}
	else if (flag == 2)
	{
		memset(Display_buff, 0, 20);
		value1 = (var[p_add * 2] << 8) + var[p_add * 2 + 1];

		if (value1 < 0)
        {
            Display_buff[kk] = 11;
            kk++;
            value = ~value1 + 1;
        }
        else
        {
            value = value1;
        }
		value = value % ((int)LtPow(10, I_num + D_num));

		for (i = 0; i < I_num; i++) // Integer part
		{
			Display_buff[kk] = value / (int)LtPow(10, I_num - i - 1 + D_num);

			if (Display_buff[kk] != 0 || flag1 == 1)
			{
				kk++;
				flag1 = 1;
			}
			value = value % (int)LtPow(10, I_num - i - 1 + D_num);
		}
		if (D_num > 0)
		{
			if (flag1 == 0)
			{
				Display_buff[kk] = 0; //"."
				kk++;
			}
			Display_buff[kk] = 10; //"."
			kk++;
		}
		else if (flag1 == 0)
		{
			Display_buff[kk] = 0; //"."
			kk++;
		}

		for (i = 0; i < D_num; i++) // Fractional part
		{
			Display_buff[kk] = value / (int)LtPow(10, D_num - i - 1);
			kk++;
			value = value % (int)LtPow(10, i - 1 + D_num);
		}

		xd = 0;
		for (i = 0; i < kk; i++)
		{
            if (S_id + Display_buff[i] >= addr_index[11]) continue; // ICON is available
            LT_ReadFlash_UI(buff1, addr_index[10] + 12 * (S_id + Display_buff[i]) + multi_language * 12 * addr_index[11], 12);
           	if (i == 0)
			{
				w0 = buff1[4] + (buff1[5] << 8);
				h0 = buff1[6] + (buff1[7] << 8);
			}

			if (Screen_DIR == 0 || Screen_DIR == 2)
				xd = xd + buff1[4] + (buff1[5] << 8);
			else if (Screen_DIR == 1 || Screen_DIR == 3)
				xd = xd + buff1[6] + (buff1[7] << 8);
		}


		if (Screen_DIR == 0)
		{
			dy = dy - y;
			if (Alig == 0)
				dx = dx - x;
			else if (Alig == 1)
				dx = dx - x - xd / 2 + 1;
			else if (Alig == 2)
				dx = dx - x - xd + 1;
		}
		else if (Screen_DIR == 1)
		{
			dx = dx - x - w0;
			if (Alig == 0)
				dy = dy - y;
			if (Alig  == 1)
				dy = dy - y - xd / 2 + 1;
			else if (Alig  == 2)
				dy = dy - y - xd + 1;
		}
		else if (Screen_DIR == 2)
		{
			dy = dy - y - h0 + 1;
			if (Alig == 0)
				dx = dx - x - w0;
			else if (Alig  == 1)
				dx = dx - x + xd / 2 - w0;
			else if (Alig  == 2)
				dx = dx - x + xd - w0;
		}
		else if (Screen_DIR == 3)
		{
			dx = dx - x;
			if (Alig == 0)
				dy = dy - y - h0;
			else if (Alig == 1)
				dy = dy - y + xd / 2 - h0;
			else if (Alig == 2)
				dy = dy - y + xd - h0;
		}

        for (i = 0; i < kk; i++)
        {
            if (S_id + Display_buff[i] >= addr_index[11])
                continue; // ICON is available
            LT_ReadFlash_UI(buff1, addr_index[10] + 12 * (S_id + Display_buff[i]) + multi_language * 12 * addr_index[11], 12);
            PICINFO[0].addr = (buff1[0]) + (buff1[1] << 8) + (buff1[2] << 16) + (buff1[3] << 24);
            PICINFO[0].w = buff1[4] + (buff1[5] << 8);
            PICINFO[0].h = buff1[6] + (buff1[7] << 8);
            PICINFO[0].len = buff1[8] + (buff1[9] << 8) + (buff1[10] << 16);
            PICINFO[0].flag = buff1[11];
            LT268_pic_to_buffer(dx + buff_x, dy + buff_y, buff_w, m_PngData,
                                0, 0, PICINFO[0].w, PICINFO[0].addr,
                    PICINFO[0].w, PICINFO[0].h, PICINFO[0].flag);

           if (Screen_DIR == 0)
				dx += PICINFO[0].w;
			else if (Screen_DIR == 1)
				dy += PICINFO[0].h;
			else if (Screen_DIR == 2)
				dx -= PICINFO[0].w;
			else if (Screen_DIR == 3)
				dy -= PICINFO[0].h;
        }
	}

	uint16_t dis_w = pic_w, dis_h = pic_h;

	if (overlay != 0xFFFF)
		Get_date_variable_Id_overlay(pic_id,overlay,x,y,buff_w,dis_h);

	if (pic_update == 0)
		LT268_buffer_to_TFT(0, 0, dis_w, m_PngData,x, y, dis_w, dis_h);
}





